using UnityEngine;

public class WeaponStrengthIndicator : MonoBehaviour
{
	public float fadeInSpeed = 2f;

	public float fadeOutSpeed = 5f;

	public float minAlpha = 0.2f;

	public float maxAlpha = 0.9f;

	private UIWidget widget;

	[SerializeField]
	private UISprite fillSprite;

	private bool show;

	private void Awake()
	{
		widget = GetComponent<UIWidget>();
	}

	public void Show()
	{
		show = true;
		if (!base.gameObject.GetActive())
		{
			base.gameObject.SetActive(true);
		}
	}

	public void Hide()
	{
		show = false;
	}

	public void SetValue(float value)
	{
		fillSprite.fillAmount = value;
	}

	private void Update()
	{
		float num = ((!show || !(fillSprite.fillAmount > 0f)) ? (0f - fadeOutSpeed) : fadeInSpeed) * Time.deltaTime;
		float num2 = ((!show) ? 0f : minAlpha);
		if (show && widget.alpha < num2)
		{
			widget.alpha = Mathf.Clamp(widget.alpha + fadeInSpeed * Time.deltaTime, 0f, maxAlpha);
		}
		else
		{
			widget.alpha = Mathf.Clamp(widget.alpha + num, num2, maxAlpha);
		}
		if (!show && widget.alpha == 0f)
		{
			disable();
		}
	}

	private void disable()
	{
		base.gameObject.SetActive(false);
	}
}
